//
//  NSString+Helper.m
//  LuckDriver
//
//  Created by pg on 15/9/22.
//  Copyright © 2015年 HCW. All rights reserved.
//

#import "NSString+Helper.h"

@implementation NSString (Helper)

+ (BOOL)isNullOrEmpty:(NSString *)string
{
    return string == nil
    || [string isEqual: (id)[NSNull null]]
    || [string isKindOfClass:[NSString class]] == NO
    || [@"" isEqualToString:string]
    || [[string stringByReplacingOccurrencesOfString:@" " withString:@""] length] == 0U
    || [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0U;
}

- (NSString *)cleanSpace
{
    //过滤字符串前后的空格
    NSString *reslut = [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    reslut = [reslut stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    return reslut;
}
//汉字的拼音
- (NSString *)pinyin
{
    NSMutableString *str = [self mutableCopy];
    CFStringTransform(( CFMutableStringRef)str, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);
    
    return [str stringByReplacingOccurrencesOfString:@" " withString:@""];
}

@end
